<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0" />
        <title>7. 函数</title>
    </head>
    <body>
        <script>
            // 返回两个数的最大值
            function max(v1, v2) {
                return v1 > v2 ? v1 : v2;
            }

            console.log(max(12, 23));
            console.log(max(23, -23));
            
            // 求解两个数直接的连续和
            function getSum(begin, end) {
                // console.log(end);
                var sum = 0;
                for(var i = begin; i <= end; i++)
                {
                    sum += i;
                }
                return sum;
            }
            console.log(getSum(1, 5));
            console.log(getSum(1, 100));
            console.log(getSum(23));

            // 返回多个参数，使用数组
            function getCoor(x, y) {
                console.log('typeof x -> ' + typeof x);
                
                var arr = new Array;
                arr.x = x;
                
                arr.y = y;
                return arr;
            }
            var mycoor = getCoor('', 100);
            console.log(mycoor.x);
            mycoor.x = 190;
            console.log(mycoor.x);
            
            var zero = getCoor(0, 0);
            console.log(zero.x);
            
        </script>
    </body>
</html>